﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using myMapObj;

namespace FakeGUI
{
    public partial class Form_SelectByAttr : Form
    {
        //字段：图层集合，要执行选择的图层，选择方法
        private moLayers _Layers;
        private moMapLayer _SelectingLayer;
        private moSelectMethodConstant _SelectMethod;

        //属性：图层集合，要执行选择的图层，选择方法
        public moLayers Layers
        {
            get { return _Layers; }
            set { _Layers = value; }
        }

        public moMapLayer SelectingLayer
        {
            get { return _SelectingLayer; }
            set { _SelectingLayer = value; }
        }

        public moSelectMethodConstant SelectMethod
        {
            get { return _SelectMethod; }
            set { _SelectMethod = value; }
        }
        
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public Form_SelectByAttr()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 构造函数：传递了图层集合参数
        /// </summary>
        /// <param name="layers"></param>
        public Form_SelectByAttr(moLayers layers)
        {
            _Layers = layers;
            InitializeComponent();
        }

        /// <summary>
        /// 窗体load事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form_SelectByAttr_Load(object sender, EventArgs e)
        {
            for(int i = 0;i<_Layers.Count;++i)
            {
                ComboBox_Layer.Items.Add(_Layers.GetItem(i).Name);
            }
            ChangeSQL(" ");
        }
        private void ChangeSQL(string layerName)
        {
            label_SQL.Text = "SELECT * FROM ";
            label_SQL.Text += layerName;
            label_SQL.Text += " WHERE";
        }
        private void Button_Verify_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException("未开发完成");
            bool IsValid = false;
            //SQL语句验证语法是否合法
            if(IsValid)
            {
                MessageBox.Show("SQL语句有效");
            }
            else
            {
                MessageBox.Show("SQL语句无效");
            }
        }

        private void Button_OK_Click(object sender, EventArgs e)
        {
            //SQL语句执行查询
            this.Close();
            throw new NotImplementedException();

        }

        private void Button_Apply_Click(object sender, EventArgs e)
        {
            //SQL语句执行查询
            throw new NotImplementedException();
        }

        private void Button_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ComboBox_Layer_SelectedIndexChanged(object sender, EventArgs e)
        {
            ChangeSQL(ComboBox_Layer.SelectedItem.ToString());
        }


    }
}
